/** Lachlan Hewson-Doherty (h201384171)
 *  Diploma of Digital and Interactive Games
 *  lachlan_doherty@live.com.au
 *  2013
 */

package cabbage.database.operations;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

import cabbage.database.utilities.DatabaseConnection;
import cabbage.model.entities.CheckinBean;

public class CheckinOps {
	
	
	
	
	

	
	
	
	
	
	private DatabaseConnection db;
	
	
	
	
	
	public CheckinOps() {
		
		//DbConnection db  = new DbConnection();
		db  = new DatabaseConnection
							();
			//db.getConnection();
	}
	
	
	
	
	
	
	
	
//	public List<CheckInBean> getAllCheckIns() throws SQLException {
//		
//		
//		Connection conn = db.getConnection();
//		
//		PreparedStatement ps = conn.prepareStatement("SELECT * FROM checkin");
//		ResultSet rs = ps.executeQuery();
//		List<CheckInBean> cbList = new ArrayList<CheckInBean>();
//		while(rs.next()) { 
//			System.out.println(rs.getInt("checkin_id"));
//			System.out.println(rs.getString("urlstring"));
//			System.out.println(rs.getTimestamp("mytimestamp"));
//			
//			CheckInBean cb = new CheckInBean(rs.getInt("checkin_id"),
//												rs.getString("urlstring"),
//													rs.getTimestamp("mytimestamp"));
//			cbList.add(cb);
//		}
//		
//		conn.close();
//		
//		return cbList;
//		
//	}
		
		
	
	
	
	
	
	
	
	
	
		
		
		public CheckinBean getCheckInByID(int checkinid) throws SQLException {
			
			CheckinBean cb = null;
			
			Connection conn = db.getConnection
										();
			
			PreparedStatement ps = conn.prepareStatement
											("SELECT * FROM checkin WHERE checkin_id=?");
			
			ps.setInt
				(1, checkinid);
			
			ResultSet rs = ps.executeQuery
									();
			
			while(rs.next())
			{ 				
				 cb = new CheckinBean
								(rs.getInt("checkin_id"),
									rs.getString("urlstring"),
										rs.getTimestamp("mytimestamp"));
			}
			
			conn.close
					();
			
			return cb;
		}

}
